﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace AviumX.AviumCore.Screen
{
    class ScreenX
    {

        private Cosmos.Hardware.VGAScreen VGAScreen = new Cosmos.Hardware.VGAScreen();//We have a strong just graduated from harvard student replacing
        //the whole VGAScreen class. Be patiant.

        //Settig up the Graphics Buffer.
        private Graphics.InteScreen Buffer = new Graphics.InteScreen(0, 0);

        public enum ScreenSizes //Toxickill - Working on a way to fix cosmos.
        {
            Resolution320,      //Do NOT change will crash cosmos.
            Resolution640
        };

        #region HTMLCOLORSW3
        private byte[] Black = { 0, 0, 0 };
        private byte[] White = { 255, 255, 255 };
        private byte[] Gray = { 128, 128, 128 };
        private byte[] Magenta = { 255, 0, 255 };
        private byte[] Purple = { 160, 32, 240 };
        private byte[] DarkPurple = { 57, 48, 88 };
        private byte[] Red = { 255, 0, 0 };
        private byte[] LightGray = { 192, 192, 192 };
        private byte[] Green = { 34, 177, 76 };
        private byte[] Lime = { 0, 255, 0 };
        private byte[] DarkGray = { 90, 90, 90 };
        private byte[] Yellow = { 255, 255, 0 };
        private byte[] AliceBlue = { 240, 248, 255 };   
        private byte[] AntiqueWhite = { 250, 235, 215 };
        private byte[] Aquamarine = { 127, 255, 212 };  
        private byte[] Azure = { 240, 255, 255 };       
        private byte[] Beige = { 245, 245, 220 };       
        private byte[] Bisque = { 255, 228, 196 };      
        private byte[] BlanchedAlmond = { 255, 235, 205 }; 
        private byte[] Blue = { 0, 0, 255 };               
        private byte[] BlueViolet = { 138, 43, 226 };      
        private byte[] Brown = { 165, 42, 42 };            
        private byte[] BurlyWood = { 222, 184, 135 };      
        private byte[] CadetBlue = { 95, 158, 160 };          
        private byte[] Chartreuse = { 127, 255, 0 };       
        private byte[] Chocolate = { 210, 105, 30 };       
        private byte[] Coral = { 255, 127, 80 };           
        private byte[] CornflowerBlue = { 100, 149, 237 }; 
        private byte[] Cornsilk = { 255, 248, 220 };       
        private byte[] Crimson = { 220, 20, 60 };          
        private byte[] Cyan = { 0, 255, 255 };             
        private byte[] DarkBlue = { 0, 0, 139 };           
        private byte[] DarkCyan = { 0, 139, 139 };         
        private byte[] DarkGrey = { 169, 169, 169 };       
        private byte[] DarkGreen = { 0, 100, 0 };          
        private byte[] DarkKhaki = { 189, 183, 107 };      
        private byte[] DarkMagneta = { 139, 0, 139 };      
        private byte[] DarkOliveGreen = { 85, 107, 47 };   
        private byte[] DarkOrange = { 255, 140, 0 };       
        private byte[] DarkOrchid = { 153, 50, 204 };      
        private byte[] DarkRed = { 139, 0, 0 };            
        private byte[] DarkSalmon = { 233, 150, 122 };     
        private byte[] DarkSeaGreen = { 143, 188, 143 };   
        private byte[] DarkSlateBlue = { 72, 61, 139 };    
        private byte[] DarkSlateGrey = { 47, 79, 79 };     
        private byte[] DarkTurquiose = { 0, 206, 209 };    
        private byte[] DarkViolet = { 148, 0, 211 };       
        private byte[] DeepPink = { 255, 20, 147 };        
        private byte[] DeepSkyBlue = { 0, 191, 255 };      
        private byte[] DimGrey = { 105, 105, 105 };        
        private byte[] DodgerBlue = { 30, 144, 255 };      
        private byte[] FireBrick = { 178, 34, 34 };        
        private byte[] FloralWhite = { 255, 250, 240 };    
        private byte[] ForestGreen = { 34, 139, 34 };     
        private byte[] Fuchsia = { 255, 0, 255 };         
        private byte[] Gainsboro = { 220, 220, 220 };     
        private byte[] GhostWhite = { 248, 248, 255 };    
        private byte[] Gold = { 255, 215, 0 };            
        private byte[] GoldenRod = { 218, 165, 32 };      
        private byte[] Web_Green = { 0, 128, 0 };         
        private byte[] GreenYellow = { 173, 255, 47 };    
        private byte[] HoneyDew = { 240, 255, 240 };      
        private byte[] HotPink = { 255, 105, 180 };       
        private byte[] IndianRed = { 205, 92, 92 };       
        private byte[] Indigo = { 75, 0, 130 };           
        private byte[] Ivory = { 255, 255, 240 };         
        private byte[] Khaki = { 240, 230, 140 };         
        private byte[] Lavender = { 230, 230, 250 };      
        private byte[] LavenderBlush = { 255, 240, 245 }; 
        private byte[] LawnGreen = { 124, 252, 0 };       
        private byte[] LemonChiffon = { 255, 250, 205 };  
        private byte[] LightBlue = { 173, 216, 230 };     
        private byte[] LightCoral = { 240, 128, 128 };    
        private byte[] LightCyan = { 224, 255, 255 };     
        private byte[] LightGoldenRodYellow = { 250, 250, 210 };
        private byte[] Web_LightGrey = { 211, 211, 211 };  
        private byte[] LightGreen = { 144, 238, 144 };     
        private byte[] LightPink = { 255, 160, 122 };      
        private byte[] LightSalmon = { 255, 160, 122 };    
        private byte[] LightSeaGreen = { 32, 178, 170 };   
        private byte[] LightSkyBlue = { 135, 206, 250 };   
        private byte[] LightSlateGrey = { 119, 136, 153 }; 
        private byte[] LightSteelBlue = { 176, 196, 222 }; 
        private byte[] LightYellow = { 255, 255, 224 };    
        private byte[] LimeGreen = { 50, 205, 50 };        
        private byte[] Linen = { 250, 240, 230 };          
        private byte[] Maroon = { 128, 0, 0 };             
        private byte[] MediumAquaMarine = { 102, 205, 170 };
        private byte[] MediumBlue = { 0, 0, 205 };        
        private byte[] MediumOrchid = { 186, 85, 211 };   
        private byte[] MediumPurple = { 147, 112, 219 };  
        private byte[] MediumSeaGreen = { 60, 179, 113 };  
        private byte[] MediumSlateBlue = { 123, 104, 238 };
        private byte[] MediumSpringGreen = { 0, 250, 154 };
        private byte[] MediumTurquoise = { 72, 209, 204 }; 
        private byte[] MediumVioletRed = { 199, 21, 133 }; 
        private byte[] MidnightBlue = { 25, 25, 112 };     
        private byte[] MintCream = { 245, 255, 250 };      
        private byte[] MintyRose = { 255, 228, 225 };      
        private byte[] Moccasin = { 255, 228, 181 };       
        private byte[] NavajoWhite = { 255, 222, 173 };    
        private byte[] Navy = { 0, 0, 128 };               
        private byte[] OldLace = { 253, 245, 230 };        
        private byte[] Olive = { 128, 128, 0 };            
        private byte[] OliveDrab = { 107, 142, 35 };       
        private byte[] Orange = { 255, 165, 0 };           
        private byte[] OrangeRed = { 255, 69, 0 };         
        private byte[] Orchid = { 218, 112, 214 };         
        private byte[] PaleGoldenRod = { 238, 232, 170 };  
        private byte[] PaleGreen = { 152, 251, 152 };      
        private byte[] PaleTurquoise = { 175, 238, 238 };  
        private byte[] PaleVioletRed = { 219, 112, 147 };  
        private byte[] PapayaWhip = { 255, 239, 213 };     
        private byte[] PeachPuff = { 255, 218, 185 };      
        private byte[] Peru = { 205, 133, 63 };            
        private byte[] Pink = { 255, 192, 203 };           
        private byte[] Plum = { 221, 160, 221 };           
        private byte[] PowderBlue = { 176, 224, 230 };     
        private byte[] Web_Purple = { 128, 0, 128 };       
        private byte[] RosyBrown = { 188, 143, 143 };      
        private byte[] RoyalBlue = { 65, 105, 225 };       
        private byte[] SaddleBrown = { 139, 69, 19 };      
        private byte[] Salmon = { 250, 128, 114 };         
        private byte[] SandyBrown = { 244, 164, 96 };      
        private byte[] SeaGreen = { 46, 139, 87 };         
        private byte[] SeaShell = { 255, 245, 238 };       
        private byte[] Sienna = { 160, 82, 45 };           
        private byte[] Silver = { 192, 192, 192 };         
        private byte[] SkyBlue = { 135, 206, 235 };        
        private byte[] SlateBlue = { 106, 90, 205 };       
        private byte[] SlateGrey = { 112, 128, 144 };      
        private byte[] Snow = { 255, 250, 250 };           
        private byte[] SpringGreen = { 0, 255, 127 };      
        private byte[] SteelBlue = { 70, 130, 180 };       
        private byte[] Tan = { 210, 180, 140 };            
        private byte[] Teal = { 0, 128, 128 };             
        private byte[] Thistle = { 216, 191, 216 };        
        private byte[] Tomato = { 255, 99, 71 };           
        private byte[] Turquoise = { 64, 224, 208 };       
        private byte[] Violet = { 238, 130, 238 };         
        private byte[] Wheat = { 245, 222, 179 };          
        private byte[] WhiteSmoke = { 245, 245, 245 };     
        private byte[] YellowGreen = { 154, 205, 50 };     
        private byte[] HenrysRandom = { 89, 36, 255 };     
        #endregion //Perfect set of colors from W3 Schools.

        public int Width = 320;         //Default 320 dimentions.
        public int Height = 200;
        //An Enum With HTML Colors.
        #region SystemColors
        public enum SystemColors
        {
            White = 1,
            Gray = 2,
            Magenta = 3,
            Purple = 4,
            DarkPurple = 5,
            Red = 6,
            LightGray = 7,
            Green = 8,
            Lime = 9,
            DarkGray = 10,
            Yellow = 11,
            AliceBlue  =  12,
            AntiqueWhite  =   13,
            Aquamarine  =   14,
            Azure  =      15,
           Beige  =        16,
           Bisque  =        17,
           BlanchedAlmond=18,
           Blue  =19,
           BlueViolet=20,
           Brown=21,
           BurlyWood=22,
           CadetBlue=23 ,    
           Chartreuse=24 ,
           Chocolate=25 ,
           Coral=26 ,
           CornflowerBlue  =    27,
           Cornsilk  =         28 ,
           Crimson  =             29 ,
           Cyan  =               30 ,
           DarkBlue  =          31 ,
           DarkCyan  =           32, 
           DarkGrey  =        33 ,
           DarkGreen  =   34 ,
           DarkKhaki  =      35 ,
           DarkMagneta  =      36 ,
           DarkOliveGreen  =  37 ,
           DarkOrange  =      38,
           DarkOrchid  =        39 ,
           DarkRed  =              40 ,
           DarkSalmon  =      41 ,
           DarkSeaGreen  =      42 ,
           DarkSlateBlue  =       43 ,
           DarkSlateGrey  =       44 ,
           DarkTurquiose  =         45, 
           DarkViolet  =          46,
           DeepPink  =           47,
           DeepSkyBlue  =         48, 
           DimGrey  =            49,
           DodgerBlue  =         50,
           FireBrick  =           51,
           FloralWhite  =      52,
           ForestGreen  =        53 ,
           Fuchsia  =             54, 
           Gainsboro  =        55 ,
           GhostWhite  =        56,
           Gold  =              57,
           GoldenRod  =     58,
           Web_Green  =            59,
           GreenYellow  =       60,
           HoneyDew  =         61,
           HotPink  =           62,
           IndianRed  =            63,
           Indigo  =              64,
           Ivory  =            65,
           Khaki  =             66,
           Lavender  =         67 ,
           LavenderBlush  =     68 ,
         LawnGreen  =          69 ,
           LemonChiffon  =    70 ,
           LightBlue  =         71, 
           LightCoral  =       72,
           LightCyan  =         73,
           LightGoldenRodYellow  =   74 ,
           Web_LightGrey  =      75, 
           LightGreen  =       76 ,
           LightPink  =         77 ,
           LightSalmon  =       78 ,
           LightSeaGreen  =       79, 
           LightSkyBlue  =      80 ,
           LightSlateGrey  =     81 ,
           LightSteelBlue  =     82, 
           LightYellow  =      83,
           LimeGreen  =         84,
           Linen  =         85,
           Maroon  =             86,
           MediumAquaMarine  =    87,
           MediumBlue  =           88,
           MediumOrchid  =      89,
           MediumPurple  =      90,
           MediumSeaGreen  =     91,
           MediumSlateBlue  =   92,
           MediumSpringGreen  =   93,
          MediumTurquoise  =    94,
           MediumVioletRed  =  95,
           MidnightBlue  =   96,
           MintCream  =      97,
           MintyRose  =      98,
           Moccasin  =       99,
           NavajoWhite  =    100,
           Navy  =           101,
           OldLace  =        102,
           Olive  =          103,
           OliveDrab  =      104,
           Orange  =         105,
           OrangeRed  =        106,
           Orchid  =           107,
           PaleGoldenRod  =    108,
           PaleGreen  =        109,
           PaleTurquoise  =    110,
           PaleVioletRed  =    111,
           PapayaWhip  =       112,
          PeachPuff  =        113,
           Peru  =             114,
           Pink  =             115,
           Plum  =            116,
           PowderBlue  =       117,
           Web_Purple  =       118,
           RosyBrown  =         119,
           RoyalBlue  =          120,
           SaddleBrown  =        121,
           Salmon  =            122,
           SandyBrown  =         123,
           SeaGreen  =           124,
          SeaShell  =          125,
          Sienna  =           126,
           Silver  =           127,
          SkyBlue  =          128,
           SlateBlue  =        129,
           SlateGrey  =        130,
           Snow  =              131,
           SpringGreen  =        132,
           SteelBlue  =         133,
           Tan  =               134,
           Teal  =             135,
           Thistle  =           136,
           Tomato  =            137,
           Turquoise  =         138,
           Violet  =           139,
            Wheat  =             140,
            WhiteSmoke  =       141 ,
            YellowGreen  =        142,
             Black = 144,
        };
#endregion //Just an Enum with the HTML Colors. // Colors

        public void Initialize(ScreenSizes Size)
        {
            //If the size that was specified is 320 then set the dimentions.
            if (Size == ScreenSizes.Resolution320)
            {
                //Set The Dimentions.
                VGAScreen.SetMode320x200x8();
                //Default values reset.
                Width = 320;
                Height = 200;
                //Creates the Buffer.
                Buffer = new Graphics.InteScreen(Width, Height);
            }
            //If the Resolution isnt 320 then go to default screensize.
            Buffer = new Graphics.InteScreen(Width, Height);
            #region SetAvailableColors
            SetColorEntry(0, Black);
            SetColorEntry(1, White);
            SetColorEntry(2, Gray);
            SetColorEntry(3, Magenta);
            SetColorEntry(4, Purple);
            SetColorEntry(5, DarkPurple);
            SetColorEntry(6, Red);
            SetColorEntry(7, LightGray);
            SetColorEntry(8, Green);
            SetColorEntry(9, Lime);
            SetColorEntry(10, DarkGray);
            SetColorEntry(11, Yellow);
            SetColorEntry(12, AliceBlue);// 12
            SetColorEntry(13, AntiqueWhite); // 13
            SetColorEntry(14, Aquamarine); // 14
            SetColorEntry(15, Azure);    // 15
            SetColorEntry(16, Beige);      // 16
            SetColorEntry(17, Bisque);      // 17
            SetColorEntry(18, BlanchedAlmond);  // 18
            SetColorEntry(19, Blue);                 // 19
            SetColorEntry(20, BlueViolet);        // 20
            SetColorEntry(21, Brown);             // 21
            SetColorEntry(22, BurlyWood);      // 22
            SetColorEntry(23, CadetBlue);         // 23     
            SetColorEntry(24, Chartreuse);       // 24 
            SetColorEntry(25, Chocolate);       // 25 
            SetColorEntry(26, Coral);       // 26 
            SetColorEntry(27, CornflowerBlue);  // 27
            SetColorEntry(28, Cornsilk);       // 28 
            SetColorEntry(29, Crimson);           // 29 
            SetColorEntry(30, Cyan);             // 30 
            SetColorEntry(31, DarkBlue);        // 31 
            SetColorEntry(32, DarkCyan);         // 32 
            SetColorEntry(33, DarkGrey);      // 33 
            SetColorEntry(34, DarkGreen); // 34 
            SetColorEntry(35, DarkKhaki);    // 35 
            SetColorEntry(36, DarkMagneta);    // 36 
            SetColorEntry(37, DarkOliveGreen);// 37 
            SetColorEntry(38, DarkOrange);    // 38 
            SetColorEntry(39, DarkOrchid);      // 39 
            SetColorEntry(40, DarkRed);            // 40 
            SetColorEntry(41, DarkSalmon);    // 41 
            SetColorEntry(42, DarkSeaGreen);    // 42 
            SetColorEntry(43, DarkSlateBlue);     // 43 
            SetColorEntry(44, DarkSlateGrey);     // 44 
            SetColorEntry(45, DarkTurquiose);       // 45 
            SetColorEntry(46, DarkViolet);        // 46
            SetColorEntry(47, DeepPink);         // 47
            SetColorEntry(48, DeepSkyBlue);       // 48 
            SetColorEntry(49, DimGrey);          // 49
            SetColorEntry(50, DodgerBlue);       // 50
            SetColorEntry(51, FireBrick);         // 51
            SetColorEntry(52, FloralWhite);    // 52
            SetColorEntry(53, ForestGreen);      // 53 
            SetColorEntry(54, Fuchsia);           // 54 
            SetColorEntry(55, Gainsboro);      // 55 
            SetColorEntry(56, GhostWhite);      // 56
            SetColorEntry(57, Gold);            // 57
            SetColorEntry(58, GoldenRod);   // 58
            SetColorEntry(59, Web_Green);          // 60
            SetColorEntry(60, GreenYellow);     // 61
            SetColorEntry(61, HoneyDew);       // 62
            SetColorEntry(62, HotPink);         // 63
            SetColorEntry(63, IndianRed);          // 64
            SetColorEntry(64, Indigo);            // 65
            SetColorEntry(65, Ivory);          // 66
            SetColorEntry(66, Khaki);           // 67
            SetColorEntry(67, Lavender);       // 68 
            SetColorEntry(68, LavenderBlush);   // 69 
            SetColorEntry(69, LawnGreen);        // 70 
            SetColorEntry(70, LemonChiffon);  // 71 
            SetColorEntry(71, LightBlue);       // 72 
            SetColorEntry(72, LightCoral);     // 73
            SetColorEntry(73, LightCyan);       // 74
            SetColorEntry(74, LightGoldenRodYellow); // 93 
            SetColorEntry(75, Web_LightGrey);    // 75 
            SetColorEntry(76, LightGreen);     // 76 
            SetColorEntry(77, LightPink);       // 77 
            SetColorEntry(78, LightSalmon);     // 78 
            SetColorEntry(79, LightSeaGreen);     // 79 
            SetColorEntry(80, LightSkyBlue);    // 80 
            SetColorEntry(81, LightSlateGrey);   // 81 
            SetColorEntry(82, LightSteelBlue);   // 82 
            SetColorEntry(83, LightYellow);    // 83 
            SetColorEntry(84, LimeGreen);       // 84
            SetColorEntry(85, Linen);       // 85
            SetColorEntry(86, Maroon);           // 86
            SetColorEntry(87, MediumAquaMarine);  // 87
            SetColorEntry(88, MediumBlue);         // 88
            SetColorEntry(89, MediumOrchid);    // 89
            SetColorEntry(90, MediumPurple);    // 90
            SetColorEntry(91, MediumSeaGreen);   // 91
            SetColorEntry(92, MediumSlateBlue); // 92
            SetColorEntry(93, MediumSpringGreen); // 98
            SetColorEntry(94, MediumTurquoise);  // 99
            SetColorEntry(95, MediumVioletRed);// 100
            SetColorEntry(96, MidnightBlue); // 101
            SetColorEntry(97, MintCream);    // 102
            SetColorEntry(98, MintyRose);    // 103
            SetColorEntry(99, Moccasin);     // 104
            SetColorEntry(100, NavajoWhite);  // 105
            SetColorEntry(101, Navy);         // 106
            SetColorEntry(102, OldLace);      // 107
            SetColorEntry(103, Olive);        // 108
            SetColorEntry(104, OliveDrab);    // 109
            SetColorEntry(105, Orange);       // 110
            SetColorEntry(106, OrangeRed);      // 111
            SetColorEntry(107, Orchid);         // 112
            SetColorEntry(108, PaleGoldenRod);  // 113
            SetColorEntry(109, PaleGreen);      // 114
            SetColorEntry(110, PaleTurquoise);  // 115
            SetColorEntry(111, PaleVioletRed);  // 116
            SetColorEntry(112, PapayaWhip);     // 117
            SetColorEntry(113, PeachPuff);      // 118
            SetColorEntry(114, Peru);           // 119
            SetColorEntry(115, Pink);           // 120
            SetColorEntry(116, Plum);          // 121
            SetColorEntry(117, PowderBlue);     // 122
            SetColorEntry(118, Web_Purple);     // 123
            SetColorEntry(119, RosyBrown); ;      // 124
            SetColorEntry(120, RoyalBlue);        // 125
            SetColorEntry(121, SaddleBrown);      // 126
            SetColorEntry(122, Salmon); ;         // 127
            SetColorEntry(123, SandyBrown);       // 128
            SetColorEntry(124, SeaGreen);         // 129
            SetColorEntry(125, SeaShell);        // 130
            SetColorEntry(126, Sienna);         // 131
            SetColorEntry(127, Silver);         // 132
            SetColorEntry(128, SkyBlue);        // 133
            SetColorEntry(129, SlateBlue);      // 134
            SetColorEntry(130, SlateGrey);      // 135
            SetColorEntry(131, Snow);            // 136
            SetColorEntry(132, SpringGreen);      // 137
            SetColorEntry(133, SteelBlue);        // 138
            SetColorEntry(134, Tan);             // 139
            SetColorEntry(135, Teal);           // 140
            SetColorEntry(136, Thistle);         // 141
            SetColorEntry(137, Tomato);          // 142
            SetColorEntry(138, Turquoise);       // 143
            SetColorEntry(139, Violet);         // 144
            SetColorEntry(140, Wheat);           // 145       
            SetColorEntry(141, WhiteSmoke);     // 147 
            SetColorEntry(142, YellowGreen);      // 149
            SetColorEntry(143, HenrysRandom);    // 150
            SetColorEntry(144, Black);
            #endregion //Dont change is perfectly fine the way it is.
        }

        public enum ConsoleResolutions
        {
            SizeSmall,
            SizeBig
        };

        //Changes the mode to the console for DEBUG use only. Optional use for Blue Screen. Maybe clear RAM here?
        public void DebugMode(ConsoleResolutions res)
        {
            //Set the screen back into console mode.
            if (res == ConsoleResolutions.SizeSmall)
            {
                VGAScreen.SetTextMode(Cosmos.Hardware.VGAScreen.TextSize.Size80x25);
            }
            if (res == ConsoleResolutions.SizeBig)
            {
                VGAScreen.SetTextMode(Cosmos.Hardware.VGAScreen.TextSize.Size80x50);
                //Set the window height
                Console.WindowHeight = Console.WindowHeight + 300;
            }
            //Clear the console.
            Console.Clear();

        }

        //Helps Set the Available Colors.
        public void SetColorEntry(int index, byte[] Pal)
        {
            VGAScreen.SetPalette(index, Pal);
        }


        #region GetPixelsNOBuffer
        public uint GetPixelIndex(uint x, uint y)
        {
            return VGAScreen.GetPixel320x200x8(x, y);
        }
        public int GetPixelIndex(int x, int y)
        {
            return (int)VGAScreen.GetPixel320x200x8((uint)x, (uint)y);
        }
        public Graphics.Color GetColor(int x, int y)
        {
            Graphics.Color newcolor = new Graphics.Color();
            Color colorfromscreen = VGAScreen.GetPaletteEntry((int)VGAScreen.GetPixel320x200x8((uint)x, (uint)y));
            newcolor = new Graphics.Color(colorfromscreen.A, colorfromscreen.R, colorfromscreen.G, colorfromscreen.B, (int)VGAScreen.GetPixel320x200x8((uint)x, (uint)y));
            return newcolor;
        }
        public Graphics.Color GetColor(uint x, uint y)
        {
            Graphics.Color newcolor = new Graphics.Color();
            Color colorfromscreen = VGAScreen.GetPaletteEntry((int)VGAScreen.GetPixel320x200x8(x, y));
            newcolor = new Graphics.Color(colorfromscreen.A, colorfromscreen.R, colorfromscreen.G, colorfromscreen.B, (int)VGAScreen.GetPixel320x200x8(x, y));
            return newcolor;
        }
        public Graphics.Color GetColor(Graphics.Vector location)
        {
            Graphics.Color newcolor = new Graphics.Color();
            Color colorfromscreen = VGAScreen.GetPaletteEntry((int)VGAScreen.GetPixel320x200x8((uint)location.x, (uint)location.y));
            newcolor = new Graphics.Color(colorfromscreen.A, colorfromscreen.R, colorfromscreen.G, colorfromscreen.B, (int)VGAScreen.GetPixel320x200x8((uint)location.x, (uint)location.y));
            return newcolor;
        }
        public Graphics.Pixel GetPixel(uint x, uint y)
        {
            Graphics.Pixel newpixel = new Graphics.Pixel();
            newpixel.Location = new Graphics.Vector(x, y);
            newpixel.GetColorsFromScreen();
            return newpixel;
        }
        public Graphics.Pixel GetPixel(int x, int y)
        {
            Graphics.Pixel newpixel = new Graphics.Pixel();
            newpixel.Location = new Graphics.Vector(x, y);
            newpixel.GetColorsFromScreen();
            return newpixel;
        }
        public Graphics.Pixel GetPixel(Graphics.Vector location)
        {
            Graphics.Pixel newpixel = new Graphics.Pixel();
            newpixel.Location = location;
            newpixel.GetColorsFromScreen();
            return newpixel;
        }
        #endregion
        #region SetPixels
        public void SetPixel(uint x, uint y, uint color)
        {
            VGAScreen.SetPixel320x200x8(x, y, color);
        }
        public void SetPixel(int x, int y, int color)
        {
            VGAScreen.SetPixel320x200x8((uint)x, (uint)y, (uint)color);
        }
        public void SetPixel(Graphics.Vector location, int color)
        {
            VGAScreen.SetPixel320x200x8((uint)location.x, (uint)location.y, (uint)color);
        }
        public void SetPixel(Graphics.Pixel pixel)
        {
            VGAScreen.SetPixel320x200x8((uint)pixel.Location.x, (uint)pixel.Location.y, (uint)pixel.ColorData.index);
        }
        #endregion

        public void ClearToSystemColor(SystemColors color)
        {
            //Clear the screen to the specified color
            VGAScreen.Clear((int)color);
            //Fixes mouse problems.
            //Mouse needed  Core.Mouse.Cursor.SaveBackBuffer();
        }

        //Adapted From PearOS An Open Sourced CosmosOS:

        #region " Double Buffer "
        //Adapted from PearOS An Open Sourced Cosmos OS.
        public void ClearBufferToColor(int Color)
        {
            uint width = (uint)Buffer.Height;
            uint height = (uint)Buffer.Width;
            if (width > height)
            {
                for (uint x = 0; x < height; x++)
                {
                    for (uint y = 0; y < width; y++)
                    {
                        SetColorInBuffer(x, y, (uint)Color);
                    }
                }
            }
            if (width == height)
            {
                for (uint x = 0; x < height; x++)
                {
                    for (uint y = 0; y < width; y++)
                    {
                        SetColorInBuffer(x, y, (uint)Color);
                    }

                }
            }
            if (width < height)
            {

                for (uint y = 0; y < width; y++)
                {
                    for (uint x = 0; x < height; x++)
                    {
                        SetColorInBuffer(x, y, (uint)Color);
                    }
                }
            }
        }
        public void ClearBufferToColor(uint Color)
        {
            /*
             * Clear the buffer to a custom color.
             */
            uint width = (uint)Buffer.Height;
            uint height = (uint)Buffer.Width;
            if (width > height)
            {
                for (uint x = 0; x < height; x++)
                {
                    for (uint y = 0; y < width; y++)
                    {
                        SetColorInBuffer(x, y, Color);
                    }
                }
            }
            if (width == height)
            {
                for (uint x = 0; x < height; x++)
                {
                    for (uint y = 0; y < width; y++)
                    {
                        SetColorInBuffer(x, y, Color);
                    }

                }
            }
            if (width < height)
            {

                for (uint y = 0; y < width; y++)
                {
                    for (uint x = 0; x < height; x++)
                    {
                        SetColorInBuffer(x, y, Color);
                    }
                }
            }
        }
        public void ClearBufferToColor(Graphics.Color color)
        {
            /*
             * Clear the buffer to a custom color.
             */
            uint width = (uint)Buffer.Height;
            uint height = (uint)Buffer.Width;
            if (width > height)
            {
                for (uint x = 0; x < height; x++)
                {
                    for (uint y = 0; y < width; y++)
                    {
                        SetColorInBuffer(x, y, (uint)color.index);
                    }
                }
            }
            if (width == height)
            {
                for (uint x = 0; x < height; x++)
                {
                    for (uint y = 0; y < width; y++)
                    {
                        SetColorInBuffer(x, y, (uint)color.index);
                    }

                }
            }
            if (width < height)
            {

                for (uint y = 0; y < width; y++)
                {
                    for (uint x = 0; x < height; x++)
                    {
                        SetColorInBuffer(x, y, (uint)color.index);
                    }
                }
            }
        }
        private uint Found = 0;
        /*
         * This is used to calculate the position of a pixel based off of a X and Y in a buffer, or as we call them Frame's.
         */
        public uint FindPixel(uint xpos, uint ypos, uint width, uint height)
        {
            /*
             * Ok so we store the pixl in the buffer in a few different ways
             * but to find out what number in the array will be that pixel
             * we loop through a for event, well thats bad, because it will slow
             * down the system, this exquation will find it for ten times faster. Making
             * pear speedy. - Matt
             */
            uint Width2 = height;
            uint Height2 = width;
            if (Width2 > Height2)
            {
                /*
                 * This does not work and I will have to fix it.
                 */
                Found = xpos * Width2 + ypos;
                return Found;
            }
            if (Width2 < Height2)
            {
                /*
                 * This implentation works.
                 */
                Found = ypos * Height2 + xpos;
                return Found;
            }
            if (Width2 == Height2)
            {
                /*
                 * I believe this one works.
                 */
                Found = ypos * Height2 + xpos;
                return Found;
            }
            return 0;
        }
        public int FindPixel(int xpos, int ypos, int width, int height)
        {
            /*
             * Ok so we store the pixl in the buffer in a few different ways
             * but to find out what number in the array will be that pixel
             * we loop through a for event, well thats bad, because it will slow
             * down the system, this exquation will find it for ten times faster. Making
             * pear speedy. - Matt
             */
            int Width2 = height;
            int Height2 = width;
            if (Width2 > Height2)
            {
                /*
                 * This does not work and I will have to fix it.
                 */

                Found = (uint)(xpos * Width2 + ypos);
                return (int)Found;
            }
            if (Width2 < Height2)
            {
                /*
                 * This implentation works.
                 */
                Found = (uint)(ypos * Height2 + xpos);
                return (int)Found;
            }
            if (Width2 == Height2)
            {
                /*
                 * I believe this one works.
                 */
                Found = (uint)(ypos * Height2 + xpos);
                return (int)Found;
            }
            return 0;
        }
        public int FindPixel(Graphics.Vector location, int width, int height)
        {
            /*
             * Ok so we store the pixl in the buffer in a few different ways
             * but to find out what number in the array will be that pixel
             * we loop through a for event, well thats bad, because it will slow
             * down the system, this exquation will find it for ten times faster. Making
             * pear speedy. - Matt
             */
            int Width2 = height;
            int Height2 = width;
            if (Width2 > Height2)
            {
                /*
                 * This does not work and I will have to fix it.
                 */

                Found = (uint)(location.x * Width2 + location.y);
                return (int)Found;
            }
            if (Width2 < Height2)
            {
                /*
                 * This implentation works.
                 */
                Found = (uint)(location.x * Height2 + location.y);
                return (int)Found;
            }
            if (Width2 == Height2)
            {
                /*
                 * I believe this one works.
                 */
                Found = (uint)(location.x * Height2 + location.y);
                return (int)Found;
            }
            return 0;
        }
        public int FindPixel(Graphics.Vector location, uint width, uint height)
        {
            /*
             * Ok so we store the pixl in the buffer in a few different ways
             * but to find out what number in the array will be that pixel
             * we loop through a for event, well thats bad, because it will slow
             * down the system, this exquation will find it for ten times faster. Making
             * pear speedy. - Matt
             */
            int Width2 = (int)height;
            int Height2 = (int)width;
            if (Width2 > Height2)
            {
                /*
                 * This does not work and I will have to fix it.
                 */

                Found = (uint)(location.x * Width2 + location.y);
                return (int)Found;
            }
            if (Width2 < Height2)
            {
                /*
                 * This implentation works.
                 */
                Found = (uint)(location.x * Height2 + location.y);
                return (int)Found;
            }
            if (Width2 == Height2)
            {
                /*
                 * I believe this one works.
                 */
                Found = (uint)(location.x * Height2 + location.y);
                return (int)Found;
            }
            return 0;
        }
        /*
         * Allows us to clear the double buffer to a system color.
         */
        public void ClearBufferToSystemColor(SystemColors Color)
        {
            /*
             * Set all the pixel in the buffer to a system color.
             */
            uint width = (uint)Buffer.Height;
            uint height = (uint)Buffer.Width;
            if (width > height)
            {
                for (uint x = 0; x < height; x++)
                {
                    for (uint y = 0; y < width; y++)
                    {
                        SetColorInBuffer(x, y, (uint)Color);
                    }

                }
            }
            if (width == height)
            {
                for (uint x = 0; x < height; x++)
                {
                    for (uint y = 0; y < width; y++)
                    {
                        SetColorInBuffer(x, y, (uint)Color);
                    }

                }
            }
            if (width < height)
            {

                for (uint y = 0; y < width; y++)
                {
                    for (uint x = 0; x < height; x++)
                    {
                        SetColorInBuffer(x, y, (uint)Color);
                    }
                }
            }
        }
        /*
         * This sets a pixel in the buffer.
         */
        public void SetPixelInBuffer(Graphics.Pixel pixel)
        {
            /*
             * Add the code for setting a pixel into the buffer. Also known as double buffering. What we are going
             * to do is draw to the buffer, and at the end, draw the entire buffer to the screen updating it, this way
             * you dont see some things getting updated and others not.
             */

            /*
             * NOTE: DO NOT USE NEEDS TO BE UPDATED TO CURRENT CODE. THANKS
             */
            Buffer.SetPixel(pixel.ColorData.index, FindPixel(pixel.Location.x, pixel.Location.y, Buffer.Width, Buffer.Height));
        }
        /*
         * This allows us to set a color in the double buffer.
         */
        public void SetColorInBuffer(uint xpos, uint ypos, uint color)
        {
            /*
             * Add the code for setting a pixel into the buffer. Also known as double buffering. What we are going
             * to do is draw to the buffer, and at the end, draw the entire buffer to the screen updating it, this way
             * you dont see some things getting updated and others not.
             */
            Buffer.SetPixel(color, FindPixel(xpos, ypos, (uint)Buffer.Width, (uint)Buffer.Height));
        }
        public void SetColorInBuffer(int xpos, int ypos, int color)
        {
            /*
             * Add the code for setting a pixel into the buffer. Also known as double buffering. What we are going
             * to do is draw to the buffer, and at the end, draw the entire buffer to the screen updating it, this way
             * you dont see some things getting updated and others not.
             */
            Buffer.SetPixel(color, (int)FindPixel((uint)xpos, (uint)ypos, (uint)Buffer.Width, (uint)Buffer.Height));
        }
        public void SetColorInBuffer(Graphics.Vector location, int color)
        {
            /*
             * Add the code for setting a pixel into the buffer. Also known as double buffering. What we are going
             * to do is draw to the buffer, and at the end, draw the entire buffer to the screen updating it, this way
             * you dont see some things getting updated and others not.
             */
            Buffer.SetPixel(color, (int)FindPixel((uint)location.x, (uint)location.y, (uint)Buffer.Width, (uint)Buffer.Height));
        }
        public void SetColorInBuffer(Graphics.Vector location, uint color)
        {
            /*
             * Add the code for setting a pixel into the buffer. Also known as double buffering. What we are going
             * to do is draw to the buffer, and at the end, draw the entire buffer to the screen updating it, this way
             * you dont see some things getting updated and others not.
             */
            Buffer.SetPixel((int)color, (int)FindPixel((uint)location.x, (uint)location.y, (uint)Buffer.Width, (uint)Buffer.Height));
        }
        public void SetColorInBuffer(uint xpos, uint ypos, Graphics.Color color)
        {
            /*
             * Add the code for setting a pixel into the buffer. Also known as double buffering. What we are going
             * to do is draw to the buffer, and at the end, draw the entire buffer to the screen updating it, this way
             * you dont see some things getting updated and others not.
             */
            Buffer.SetPixel(color.index, (int)FindPixel(xpos, ypos, (uint)Buffer.Width, (uint)Buffer.Height));
        }
        public void SetColorInBuffer(int xpos, int ypos, Graphics.Color color)
        {
            /*
             * Add the code for setting a pixel into the buffer. Also known as double buffering. What we are going
             * to do is draw to the buffer, and at the end, draw the entire buffer to the screen updating it, this way
             * you dont see some things getting updated and others not.
             */
            Buffer.SetPixel(color.index, (int)FindPixel((uint)xpos, (uint)ypos, (uint)Buffer.Width, (uint)Buffer.Height));
        }
        public void SetColorInBuffer(Graphics.Vector location, Graphics.Color color)
        {
            /*
             * Add the code for setting a pixel into the buffer. Also known as double buffering. What we are going
             * to do is draw to the buffer, and at the end, draw the entire buffer to the screen updating it, this way
             * you dont see some things getting updated and others not.
             */
            Buffer.SetPixel(color.index, (int)FindPixel((uint)location.x, (uint)location.y, (uint)Buffer.Width, (uint)Buffer.Height));
        }
        /*
         * Allows us to get a pixel from the buffer using the PIXEL class
         */
        public Graphics.Pixel GetPixelInBuffer(int x, int y)
        {
            Graphics.Pixel PixelFind = new Graphics.Pixel();
            /*
             * Note: this will return the index number of the pixel
             * we will then use VGAScreen.GetPallete Entry and set the RGB values
             * of the pixel into the new pixel we are going to return and we will
             * set the index value of the pixel so if need to know what the index was, we
             * can get that.
             */
            PixelFind.Location.x = x;
            PixelFind.Location.y = y;
            Color colorfromscreen = VGAScreen.GetPaletteEntry(Buffer.GetPixel(FindPixel(x, y, Buffer.Width, Buffer.Height)));
            PixelFind.ColorData = new Graphics.Color(colorfromscreen.A, colorfromscreen.R, colorfromscreen.G, colorfromscreen.B, Buffer.GetPixel(FindPixel(x, y, Buffer.Width, Buffer.Height)));
            return PixelFind;
        }
        public Graphics.Pixel GetPixelInBuffer(uint x, uint y)
        {
            Graphics.Pixel PixelFind = new Graphics.Pixel();
            /*
             * Note: this will return the index number of the pixel
             * we will then use VGAScreen.GetPallete Entry and set the RGB values
             * of the pixel into the new pixel we are going to return and we will
             * set the index value of the pixel so if need to know what the index was, we
             * can get that.
             */
            PixelFind.Location.x = (int)x;
            PixelFind.Location.y = (int)y;
            Color colorfromscreen = VGAScreen.GetPaletteEntry(Buffer.GetPixel(FindPixel((int)x, (int)y, Buffer.Width, Buffer.Height)));
            PixelFind.ColorData = new Graphics.Color(colorfromscreen.A, colorfromscreen.R, colorfromscreen.G, colorfromscreen.B, Buffer.GetPixel(FindPixel((int)x, (int)y, Buffer.Width, Buffer.Height)));
            return PixelFind;
        }
        public Graphics.Pixel GetPixelInBuffer(Graphics.Vector location)
        {
            Graphics.Pixel PixelFind = new Graphics.Pixel();
            /*
             * Note: this will return the index number of the pixel
             * we will then use VGAScreen.GetPallete Entry and set the RGB values
             * of the pixel into the new pixel we are going to return and we will
             * set the index value of the pixel so if need to know what the index was, we
             * can get that.
             */
            PixelFind.Location = location;
            Color colorfromscreen = VGAScreen.GetPaletteEntry(Buffer.GetPixel(FindPixel(location.x, location.y, Buffer.Width, Buffer.Height)));
            PixelFind.ColorData = new Graphics.Color(colorfromscreen.A, colorfromscreen.R, colorfromscreen.G, colorfromscreen.B, Buffer.GetPixel(FindPixel(location.x, location.y, Buffer.Width, Buffer.Height)));
            return PixelFind;
        }
        /*
         * Allows us to get a color from inside the buffer.
         */
        public uint GetColorIndexInBuffer(uint xpos, uint ypos)
        {

            /*
             * Note: this will return the index number of the pixel
             * we will then use VGAScreen.GetPallete Entry and set the RGB values
             * of the pixel into the new pixel we are going to return and we will
             * set the index value of the pixel so if need to know what the index was, we
             * can get that.
             */
            return Buffer.GetPixel(FindPixel(xpos, ypos, (uint)Buffer.Width, (uint)Buffer.Height));
        }
        public int GetColorIndexInBuffer(int xpos, int ypos)
        {
            /*
             * Note: this will return the index number of the pixel
             * we will then use VGAScreen.GetPallete Entry and set the RGB values
             * of the pixel into the new pixel we are going to return and we will
             * set the index value of the pixel so if need to know what the index was, we
             * can get that.
             */
            return (int)Buffer.GetPixel(FindPixel((uint)xpos, (uint)ypos, (uint)Buffer.Width, (uint)Buffer.Height)); ;
        }
        public int GetColorIndexInBuffer(Graphics.Vector location)
        {
            /*
             * Note: this will return the index number of the pixel
             * we will then use VGAScreen.GetPallete Entry and set the RGB values
             * of the pixel into the new pixel we are going to return and we will
             * set the index value of the pixel so if need to know what the index was, we
             * can get that.
             */
            return (int)Buffer.GetPixel(FindPixel((uint)location.x, (uint)location.y, (uint)Buffer.Width, (uint)Buffer.Height)); ;
        }
        public Graphics.Color GetColorInBuffer(int xpos, int ypos)
        {
            /*
             * Note: this will return the index number of the pixel
             * we will then use VGAScreen.GetPallete Entry and set the RGB values
             * of the pixel into the new pixel we are going to return and we will
             * set the index value of the pixel so if need to know what the index was, we
             * can get that.
             */
            Graphics.Color newcolor = new Graphics.Color();
            Color colorfromscreen = VGAScreen.GetPaletteEntry(Buffer.GetPixel(FindPixel(xpos, ypos, Buffer.Width, Buffer.Height)));
            newcolor = new Graphics.Color(colorfromscreen.A, colorfromscreen.R, colorfromscreen.G, colorfromscreen.B, Buffer.GetPixel(FindPixel(xpos, ypos, Buffer.Width, Buffer.Height)));
            return newcolor;
        }
        public Graphics.Color GetColorInBuffer(uint xpos, uint ypos)
        {
            /*
             * Note: this will return the index number of the pixel
             * we will then use VGAScreen.GetPallete Entry and set the RGB values
             * of the pixel into the new pixel we are going to return and we will
             * set the index value of the pixel so if need to know what the index was, we
             * can get that.
             */
            Graphics.Color newcolor = new Graphics.Color();
            Color colorfromscreen = VGAScreen.GetPaletteEntry(Buffer.GetPixel(FindPixel((int)xpos, (int)ypos, Buffer.Width, Buffer.Height)));
            newcolor = new Graphics.Color(colorfromscreen.A, colorfromscreen.R, colorfromscreen.G, colorfromscreen.B, Buffer.GetPixel(FindPixel((int)xpos, (int)ypos, Buffer.Width, Buffer.Height)));
            return newcolor;
        }
        public Graphics.Color GetColorInBuffer(Graphics.Vector location)
        {
            /*
             * Note: this will return the index number of the pixel
             * we will then use VGAScreen.GetPallete Entry and set the RGB values
             * of the pixel into the new pixel we are going to return and we will
             * set the index value of the pixel so if need to know what the index was, we
             * can get that.
             */
            Graphics.Color newcolor = new Graphics.Color();
            Color colorfromscreen = VGAScreen.GetPaletteEntry(Buffer.GetPixel(FindPixel(location.x, location.y, Buffer.Width, Buffer.Height)));
            newcolor = new Graphics.Color(colorfromscreen.A, colorfromscreen.R, colorfromscreen.G, colorfromscreen.B, Buffer.GetPixel(FindPixel(location.x, location.y, Buffer.Width, Buffer.Height)));
            return newcolor;
        }
        /*
         * This will draw the entire buffer to the screen.
         */
        public void DrawBufferToScreen()
        {
            /*
             * Draw the buffer to the screen
             */
            RestoreFrame(0, 0, Buffer);
        }
        /*
         * This will save the screen to the buffer.
         */
        public void SaveScreenToBuffer()
        {
            /*
             * Save the screen into the buffer.
             */
            SaveFrame(0, 0, Buffer);
        }
        #endregion

        #region SaveInteScreen

        public void SaveFrame(uint xpos, uint ypos, Graphics.InteScreen image)
        {
            //inverted.
            uint width = (uint)image.Height;
            uint height = (uint)image.Width;
            if (width > height)
            {
                uint n = 0;
                for (uint x = 0; x < height; x++)
                {
                    for (uint y = 0; y < width; y++)
                    {
                        uint I = VGAScreen.GetPixel320x200x8(xpos + x, ypos + y);
                        //Commented out this: xpos + x, ypos + y,
                        image.SetPixel(I, n);
                        n += 1;
                    }

                }
            }
            if (width == height)
            {
                uint n = 0;
                for (uint x = 0; x < height; x++)
                {
                    for (uint y = 0; y < width; y++)
                    {
                        uint I = VGAScreen.GetPixel320x200x8(xpos + x, ypos + y);
                        //Commented out this: xpos + x, ypos + y,
                        image.SetPixel(I, n);
                        n += 1;
                    }

                }
            }
            if (width < height)
            {
                uint n = 0;
                for (uint y = 0; y < width; y++)
                {
                    for (uint x = 0; x < height; x++)
                    {
                        uint I = VGAScreen.GetPixel320x200x8(xpos + x, ypos + y);
                        //Commented out this: xpos + x, ypos + y,
                        image.SetPixel(I, n);
                        n += 1;
                    }

                }
            }
        }
        public void SaveFrameFromBuffer(uint xpos, uint ypos, Graphics.InteScreen image)
        {
            //inverted.
            uint width = (uint)image.Height;
            uint height = (uint)image.Width;
            if (width > height)
            {
                uint n = 0;
                for (uint x = 0; x < height; x++)
                {
                    for (uint y = 0; y < width; y++)
                    {
                        uint I = (uint)GetColorIndexInBuffer(xpos + x, ypos + y);
                        //Commented out this: xpos + x, ypos + y,
                        image.SetPixel(I, n);
                        n += 1;
                    }

                }
            }
            if (width == height)
            {
                uint n = 0;
                for (uint x = 0; x < height; x++)
                {
                    for (uint y = 0; y < width; y++)
                    {
                        uint I = (uint)GetColorIndexInBuffer(xpos + x, ypos + y);
                        //Commented out this: xpos + x, ypos + y,
                        image.SetPixel(I, n);
                        n += 1;
                    }

                }
            }
            if (width < height)
            {
                uint n = 0;
                for (uint y = 0; y < width; y++)
                {
                    for (uint x = 0; x < height; x++)
                    {
                        uint I = (uint)GetColorIndexInBuffer(xpos + x, ypos + y);
                        //Commented out this: xpos + x, ypos + y,
                        image.SetPixel(I, n);
                        n += 1;
                    }

                }
            }
        }
        public void RestoreFrame(uint xpos, uint ypos, Graphics.InteScreen image)
        {
            //inverted.
            uint width = (uint)image.Height;
            uint height = (uint)image.Width;
            if (width > height)
            {
                uint n = 0;
                for (uint x = 0; x < height; x++)
                {
                    for (uint y = 0; y < width; y++)
                    {
                        //Commented out this: xpos + x, ypos + y,
                        uint I = image.GetPixel(n);
                        VGAScreen.SetPixel320x200x8(xpos + x, ypos + y, I);
                        n += 1;
                    }

                }
            }
            if (width == height)
            {
                uint n = 0;
                for (uint x = 0; x < height; x++)
                {
                    for (uint y = 0; y < width; y++)
                    {
                        //Commented out this: xpos + x, ypos + y,
                        uint I = image.GetPixel(n);
                        VGAScreen.SetPixel320x200x8(xpos + x, ypos + y, I);
                        n += 1;
                    }

                }
            }
            if (width < height)
            {
                uint n = 0;
                for (uint y = 0; y < width; y++)
                {
                    for (uint x = 0; x < height; x++)
                    {
                        //Commented out this: xpos + x, ypos + y,
                        uint I = image.GetPixel(n);
                        SetPixel(xpos + x, ypos + y, I);
                        n += 1;
                    }

                }
            }
        }
        public void RestoreFrameIntoBuffer(uint xpos, uint ypos, Graphics.InteScreen image)
        {
            //inverted.
            uint width = (uint)image.Height;
            uint height = (uint)image.Width;
            if (width > height)
            {
                uint n = 0;
                for (uint x = 0; x < height; x++)
                {
                    for (uint y = 0; y < width; y++)
                    {
                        //Commented out this: xpos + x, ypos + y,
                        uint I = image.GetPixel(n);
                        SetColorInBuffer(xpos + x, ypos + y, I);
                        n += 1;
                        //uint I = image.GetPixel(FindPixel(xpos + x, ypos + y, (uint)image.Width, (uint)image.Height));
                        //SetColorInBuffer(xpos + x, ypos + y, I);
                    }

                }
            }
            if (width == height)
            {
                uint n = 0;
                for (uint x = 0; x < height; x++)
                {
                    for (uint y = 0; y < width; y++)
                    {
                        //Commented out this: xpos + x, ypos + y,
                        uint I = image.GetPixel(n);
                        SetColorInBuffer(xpos + x, ypos + y, I);
                        n += 1;
                        //uint I = GetColorInBuffer(xpos + x, ypos + y);
                        //SetColorInBuffer(xpos + x, ypos + y, I);
                    }

                }
            }
            if (width < height)
            {
                uint n = 0;
                for (uint y = 0; y < width; y++)
                {
                    for (uint x = 0; x < height; x++)
                    {
                        //Commented out this: xpos + x, ypos + y,
                        uint I = image.GetPixel(n);
                        SetColorInBuffer(xpos + x, ypos + y, I);
                        n += 1;
                        //uint I = GetColorInBuffer(xpos + x, ypos + y);
                        //SetColorInBuffer(xpos + x, ypos + y, I);
                    }

                }
            }
        }
        #endregion

        #region " DrawingFunctions "

        public void DrawFrameWhite(uint[] Arr, int width, int length, int xpixel, int ypixel)
        {
            uint x = 0, y = 0;
            int texnumwid = 0;
            int textnumlen = 0;
            int i;
            int t;
            int count = 0;
            if (xpixel + width > this.Width)
            {

            }
            for (i = 0; i < length; i++)
            {
                for (t = 0; t < width; t++, count++)
                {
                    if (Arr[count] == 1)
                    {
                        VGAScreen.SetPixel320x200x8(x + (uint)t + (uint)texnumwid + (uint)xpixel, y + (uint)i + (uint)textnumlen + (uint)ypixel, (uint)SystemColors.White);
                    }
                }
            }
        }
        public void DrawFrameBlack(uint[] Arr, int width, int length, int xpixel, int ypixel)
        {
            uint x = 0, y = 0;
            int texnumwid = 0;
            int textnumlen = 0;
            int i;
            int t;
            int count = 0;
            for (i = 0; i < length; i++)
            {
                for (t = 0; t < width; t++, count++)
                {
                    if (Arr[count] == 1)
                    {
                        VGAScreen.SetPixel320x200x8(x + (uint)t + (uint)texnumwid + (uint)xpixel, y + (uint)i + (uint)textnumlen + (uint)ypixel, (uint)SystemColors.Black);
                    }
                }
            }
        }
        public void DrawFrameBlackInBuffer(uint[] Arr, int width, int length, int xpixel, int ypixel)
        {
            uint x = 0, y = 0;
            int texnumwid = 0;
            int textnumlen = 0;
            int i;
            int t;
            int count = 0;
            for (i = 0; i < length; i++)
            {
                for (t = 0; t < width; t++, count++)
                {
                    if (Arr[count] == 1)
                    {
                        SetColorInBuffer(x + (uint)t + (uint)texnumwid + (uint)xpixel, y + (uint)i + (uint)textnumlen + (uint)ypixel, (uint)SystemColors.Black);
                    }
                }
            }
        }
        public void DrawFrameBasedOffOfSystemColorsInBuffer(uint[] Arr, int width, int length, int xpixel, int ypixel)
        {
            uint x = 0, y = 0;
            int texnumwid = 0;
            int textnumlen = 0;
            int i;
            int t;
            int count = 0;
            if (xpixel + width > this.Width)
            {
                width = this.Width - xpixel;
            }
            if (ypixel + length > this.Height)
            {
                length = this.Height - ypixel;
            }
            if (xpixel <= 0)
            {
                xpixel = 0;
            }
            if (ypixel <= 0)
            {
                ypixel = 0;
            }
            for (i = 0; i < length; i++)
            {
                for (t = 0; t < width; t++, count++)
                {
                    if (Arr[count] == 0)
                    {
                        //Do nothing, these are non drawn pixels.
                    }
                    else
                    {
                        SetColorInBuffer(x + (uint)t + (uint)texnumwid + (uint)xpixel, y + (uint)i + (uint)textnumlen + (uint)ypixel, (uint)Arr[count]);
                    }
                }
            }
        }
        public void DrawFrameWhiteInBuffer(uint[] Arr, int width, int length, int xpixel, int ypixel)
        {
            uint x = 0, y = 0;
            int texnumwid = 0;
            int textnumlen = 0;
            int i;
            int t;
            int count = 0;
            if (xpixel + width > this.Width)
            {
                width = this.Width - xpixel;
            }
            if (ypixel + length > this.Height)
            {
                length = this.Height - ypixel;
            }
            if (xpixel <= 0)
            {
                xpixel = 0;
            }
            if (ypixel <= 0)
            {
                ypixel = 0;
            }
            for (i = 0; i < length; i++)
            {
                for (t = 0; t < width; t++, count++)
                {
                    if (Arr[count] == 1)
                    {
                        SetColorInBuffer(x + (uint)t + (uint)texnumwid + (uint)xpixel, y + (uint)i + (uint)textnumlen + (uint)ypixel, (uint)SystemColors.White);
                    }
                }
            }
        }
        public void DrawFrameBlackAndWhiteInBuffer(uint[] Arr, int width, int length, int xpixel, int ypixel)
        {
            uint x = 0, y = 0;
            int texnumwid = 0;
            int textnumlen = 0;
            int i;
            int t;
            int count = 0;
            for (i = 0; i < length; i++)
            {
                for (t = 0; t < width; t++, count++)
                {
                    if (Arr[count] == 1)
                    {
                        SetColorInBuffer(x + (uint)t + (uint)texnumwid + (uint)xpixel, y + (uint)i + (uint)textnumlen + (uint)ypixel, (uint)SystemColors.Black);
                    }
                    if (Arr[count] == 2)
                    {
                        SetColorInBuffer(x + (uint)t + (uint)texnumwid + (uint)xpixel, y + (uint)i + (uint)textnumlen + (uint)ypixel, (uint)SystemColors.White);
                    }
                }
            }
        }
        public void DrawFrameSystemColor(uint[] Arr, int width, int length, int xpixel, int ypixel, SystemColors color)
        {
            uint x = 0, y = 0;
            int texnumwid = 0;
            int textnumlen = 0;
            int i;
            int t;
            int count = 0;
            for (i = 0; i < length; i++)
            {
                for (t = 0; t < width; t++, count++)
                {
                    if (Arr[count] == 1)
                    {
                        VGAScreen.SetPixel320x200x8(x + (uint)t + (uint)texnumwid + (uint)xpixel, y + (uint)i + (uint)textnumlen + (uint)ypixel, (uint)color);
                    }
                }
            }
        }
        public void DrawFrameSystemColorInBuffer(uint[] Arr, int width, int length, int xpixel, int ypixel, SystemColors color)
        {
            uint x = 0, y = 0;
            int texnumwid = 0;
            int textnumlen = 0;
            int i;
            int t;
            int count = 0;
            if (xpixel + width > this.Width)
            {
                width = this.Width - xpixel;
            }
            if (ypixel + length > this.Height)
            {
                length = this.Height - ypixel;
            }
            if (xpixel <= 0)
            {
                xpixel = 0;
            }
            if (ypixel <= 0)
            {
                ypixel = 0;
            }
            for (i = 0; i < length; i++)
            {
                for (t = 0; t < width; t++, count++)
                {
                    if (Arr[count] == 1)
                    {
                        SetColorInBuffer(x + (uint)t + (uint)texnumwid + (uint)xpixel, y + (uint)i + (uint)textnumlen + (uint)ypixel, (uint)color);
                    }
                }
            }
        }
        public void DrawRect(uint xpixel, uint ypixel, uint width, uint length, uint color)
        {
            if (xpixel + width > this.Width)
            {
                width = (uint)this.Width - xpixel;
            }
            if (ypixel + length > this.Height)
            {
                //length = this.Height - ypixel;
                length = (uint)this.Height - ypixel;
            }
            if (xpixel <= 0)
            {
                xpixel = 0;
            }
            if (ypixel <= 0)
            {
                ypixel = 0;
            }
            for (uint bb = xpixel; bb < xpixel + width; bb++)
            {

                for (uint cc = ypixel; cc < ypixel + length; cc++)
                {
                    VGAScreen.SetPixel320x200x8(bb, cc, color);
                }
            }
        }
        public void DrawRectToBuffer(uint xpixel, uint ypixel, uint width, uint length, uint color)
        {
            if (xpixel + width > this.Width)
            {
                width = (uint)this.Width - xpixel;
            }
            if (ypixel + length > this.Height)
            {
                //length = this.Height - ypixel;
                length = (uint)this.Height - ypixel;
            }
            for (uint bb = xpixel; bb < xpixel + width; bb++)
            {

                for (uint cc = ypixel; cc < ypixel + length; cc++)
                {
                    SetColorInBuffer(bb, cc, color);
                }
            }
        }
        public void DrawSquare(uint x, uint y, uint Length, uint color)
        {

            for (uint bb = x; bb < x + Length; bb++)
            {

                for (uint cc = y; cc < y + Length; cc++)
                {
                    VGAScreen.SetPixel320x200x8(bb, cc, color);
                }
            }
        }
        public void DrawSquareToBuffer(uint x, uint y, uint Length, uint color)
        {

            for (uint bb = x; bb < x + Length; bb++)
            {

                for (uint cc = y; cc < y + Length; cc++)
                {
                    SetColorInBuffer(bb, cc, color);
                }
            }
        }
        #endregion

        //End Adapted Section.
    }
}
